﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Data.Dynamics
{
    [Jemgine.Engine.Category("Primitive"), Jemgine.Engine.Node]
    public class PrismaticJoint : Dynamic
    {
       
        public bool enableLimit { get; set; }
        public float lowerTranslation { get; set; }
        public float upperTranslation { get; set; }
        public bool enableMotor { get; set; }
        public float maxMotorForce { get; set; }
        public float motorSpeed { get; set; }

        public PrismaticJoint()
        {
            AddAnchor();
            AddAnchor();
        }

        public override Box2D.XNA.JointDef GetJointDef()
        {
            var A = GetEntityBody(Anchors[0].Target);
            var B = GetEntityBody(Anchors[1].Target);

            if (A == null || B == null) return null;

            var Def = new Box2D.XNA.PrismaticJointDef();
            Def.Initialize(A, B, Anchors[0].Position, Vector2.Normalize(Anchors[1].Position - Anchors[0].Position));
            Def.enableLimit = enableLimit;
            Def.lowerTranslation = lowerTranslation;
            Def.upperTranslation = upperTranslation;
            Def.enableMotor = true;
            Def.motorSpeed = motorSpeed;
            Def.maxMotorForce = maxMotorForce;

            Def.collideConnected = ConnectedCollide;

            return Def;
        }
    }
}
